package com.easy.demo.controller;

import com.basic.domain.ResultVo;
import com.easy.annotations.RestMapping;
import com.easy.demo.entity.User;
import com.easy.demo.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器层
 *
 * @author LZH
 * @version 1.0.6
 * @since 2023/06/06
 */
@RestMapping("user")
public class UserController {

    @Resource
    private UserService service;

    /**
     * 查询所有数据
     *
     * @return {@link List}
     */
    @GetMapping
    public ResultVo<List<User>> list() {
        return ResultVo.ok(service.getList());
    }

    /**
     * 修改数据
     *
     * @param user {@link User}
     * @return 是否成功
     */
    @PutMapping
    public ResultVo<Void> update(@RequestBody User user) {
        return service.update(user) ? ResultVo.ok() : ResultVo.fail();
    }

}
